<!--
 * @Author: 赵克强 huohuo625@163.com
 * @Date: 2023-10-17 10:13:29
 * @LastEditors: 赵克强 huohuo625@163.com
 * @LastEditTime: 2025-04-17 10:43:51
 * @FilePath: \hy-ui\src\App.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div id="app">
    <router-view />
    <theme-picker />
    <!-- <iframe ref="authIframe" v-if="this.$route.path !== '/login'" v-show="iframeConfig.iframeShow" sandbox="allow-scripts allow-same-origin" allow="fullscreen"
      @load="sendTokenToIframe" src="http://192.168.0.44:82/ai"
      :style="{ position: 'absolute', bottom: iframeConfig.drawer ? 0 : '40px', 'z-index': 999999, right: '0', width: iframeConfig.width, height: iframeConfig.height, }"
      frameborder="no">

    </iframe> -->
  </div>
</template>

<script>
import ThemePicker from "@/components/ThemePicker";

export default {
  name: "App",
  components: { ThemePicker },
  data() {
    return {
      iframeConfig: {
        iframeShow: false,
        width: '80px',
        height: '80px',
        drawer:false
      }
    }
  },
  mounted() {
    window.addEventListener('message', this.handleMessage);
    sessionStorage.removeItem("designParams");
  },
  beforeDestroy() {
    window.removeEventListener('message', this.handleMessage);
  },
  metaInfo() {
    return {
      title: this.$store.state.settings.dynamicTitle && this.$store.state.settings.title,
      titleTemplate: title => {
        return title ? `${title} - ${process.env.VUE_APP_TITLE}` : process.env.VUE_APP_TITLE
      }
    }
  },
methods: {
  handleMessage(event) {
      if (event.data.type === "iframeConfig") {
        this.iframeConfig = { ...this.iframeConfig, ...event.data?.data }
        return
      }
      if (event.data.type === "iframeClose") {
        this.iframeConfig = { ...this.iframeConfig, width: '80px', height: '80px',drawer:false }
        return
      }
      // console.log(event);
    },
    sendTokenToIframe() {
      const iframe = this.$refs.authIframe;
      iframe.contentWindow.postMessage({
        type: 'SET_TOKEN',
        token: 'token'
      },'*')
    }
},
};
</script>
<style scoped>
#app .theme-picker {
  display: none;
}
</style>
